
from django.db import models

from django.db import models
from apps.users.models import User




class OrderInfo(models.Model):
    """订单信息"""
    order_id = models.CharField(max_length=64, primary_key=True, verbose_name="订单号")
    user = models.ForeignKey(User, related_name="orders", on_delete=models.PROTECT, verbose_name="下单用户")
    total_day = models.IntegerField(default=0, verbose_name="充值天数")
    total_count = models.IntegerField(default=0, verbose_name="充值总数")
    total_amount = models.IntegerField(default=0, verbose_name="商品总金额")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    expire_time = models.DateField(null=True, verbose_name='到期日期')
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = "tb_order_info"
        verbose_name = '订单基本信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.order_id



class Payment(models.Model):
    """支付信息"""
    order = models.ForeignKey(OrderInfo, on_delete=models.CASCADE, related_name='users', null=True,verbose_name='用户')
    trade_id = models.CharField(max_length=100, unique=True, null=True, blank=True, verbose_name="支付编号")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_payment'
        verbose_name = '支付信息'
        verbose_name_plural = verbose_name



